﻿/*
 * BlockBitmapSource
 * 
 * initial implementation : 3.12.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Runtime.InteropServices;

namespace Petra.Gis.ImagingServices.Tiff
{

  public partial class BlockBitmapSource : BitmapSource
  {



    #region Freezable

    /// <summary>
    ///     Creates an instance of a BlockBitmapSource.
    /// </summary>
    /// <returns>
    ///     The new instance.
    /// </returns>
    /// <remarks>
    ///     The default implementation uses reflection to create a new
    ///     instance of this type.  Derived classes may override this
    ///     method if they wish to provide a more performant
    ///     implementation, or if their type does not have a public
    ///     default constructor.
    /// </remarks>
    protected override Freezable CreateInstanceCore()
    {
      return (Freezable)Activator.CreateInstance(this.GetType());
    }

    /// <summary>
    ///     Copies data into a cloned instance.
    /// </summary>
    /// <param name="source">
    ///     The original instance to copy data from.
    /// </param>
    /// <remarks>
    ///     When Freezable is cloned, WPF will make deep clones of all
    ///     writable, locally-set properties including expressions. The
    ///     property's base value is copied -- not the current value. WPF
    ///     skips read only DPs.
    ///     
    ///     If you derive from this class and have additional non-DP state
    ///     that should be transfered to copies, you should override the
    ///     CopyCommon method.
    /// </remarks>
    protected sealed override void CloneCore(Freezable source)
    {
      base.CloneCore(source);

      BlockBitmapSource customBitmapSource = (BlockBitmapSource)source;
      CopyCore(customBitmapSource, /*useCurrentValue*/ false, /*willBeFrozen*/ false);
    }

    /// <summary>
    ///     Copies data into a cloned instance.
    /// </summary>
    /// <param name="source">
    ///     The original instance to copy data from.
    /// </param>
    /// <remarks>
    ///     When a Freezable's "current value" is cloned, WPF will make
    ///     deep clones of the "current values" of all writable,
    ///     locally-set properties. This has the effect of resolving
    ///     expressions to their values. WPF skips read only DPs.
    ///     
    ///     If you derive from this class and have additional non-DP state
    ///     that should be transfered to copies, you should override the
    ///     CopyCommon method.
    /// </remarks>
    protected sealed override void CloneCurrentValueCore(Freezable source)
    {
      base.CloneCurrentValueCore(source);

      BlockBitmapSource customBitmapSource = (BlockBitmapSource)source;
      CopyCore(customBitmapSource, /*useCurrentValue*/ true, /*willBeFrozen*/ false);
    }

    /// <summary>
    ///     Copies data into a cloned instance.
    /// </summary>
    /// <param name="source">
    ///     The original instance to copy data from.
    /// </param>
    /// <remarks>
    ///     Freezable.GetAsFrozen is semantically equivalent to
    ///     Freezable.Clone().Freeze(), except that you can avoid copying
    ///     any portions of the Freezable graph which are already frozen.
    ///     
    ///     If you derive from this class and have additional non-DP state
    ///     that should be transfered to copies, you should override the
    ///     CopyCommon method.
    /// </remarks>
    protected sealed override void GetAsFrozenCore(Freezable source)
    {
      base.GetAsFrozenCore(source);

      BlockBitmapSource customBitmapSource = (BlockBitmapSource)source;
      CopyCore(customBitmapSource, /*useCurrentValue*/ false, /*willBeFrozen*/ true);
    }

    /// <summary>
    ///     Copies data into a cloned instance.
    /// </summary>
    /// <param name="source">
    ///     The original instance to copy data from.
    /// </param>
    /// <remarks>
    ///     Freezable.GetCurrentValueAsFrozen is semantically equivalent to
    ///     Freezable.CloneCurrentValue().Freeze(), except that WPF will
    ///     avoid copying any portions of the Freezable graph which are
    ///     already frozen.
    ///     
    ///     If you derive from this class and have additional non-DP state
    ///     that should be transfered to copies, you should override the
    ///     CopyCommon method.
    /// </remarks>
    protected sealed override void GetCurrentValueAsFrozenCore(Freezable source)
    {
      base.GetCurrentValueAsFrozenCore(source);

      BlockBitmapSource customBitmapSource = (BlockBitmapSource)source;
      CopyCore(customBitmapSource, /*useCurrentValue*/ true, /*willBeFrozen*/ true);
    }

    /// <summary>
    ///     Copies data into a cloned instance.
    /// </summary>
    /// <param name="original">
    ///     The original instance to copy data from.
    /// </param>
    /// <param name="useCurrentValue">
    ///     Whether or not to copy the current value of expressions, or the
    ///     expressions themselves.
    /// </param>
    /// <param name="willBeFrozen">
    ///     Indicates whether or not the clone will be frozen.  If the
    ///     clone will be immediately frozen, there is no need to clone
    ///     data that is already frozen, you can just share the instance.
    /// </param>
    /// <remarks>
    ///     Override this method if you have additional non-DP state that
    ///     should be transfered to clones.
    /// </remarks>
    protected virtual void CopyCore(BlockBitmapSource original, bool useCurrentValue, bool willBeFrozen)
    {
    }

    #endregion Freezable



  }
}
